<CFSET tmpIdDet = GetEntry.DOCNUMBER>
<CFQUERY NAME="qryECINTRNGEMP" DATASOURCE="#client.company_dsn#">
	SELECT * FROM ECINTRAININGEMP
	WHERE DOCNUMBER = '#tmpIdDet#'
</CFQUERY>
<CFQUERY NAME="qryECINTRNGENROLLED" DATASOURCE="#client.company_dsn#">
	SELECT * FROM ECINTRNGENROLLED
	WHERE DOCNUMBER = '#tmpIdDet#'
</CFQUERY>

<CFQUERY NAME="qryCINTRNGEVENT" DATASOURCE="#client.company_dsn#">
	SELECT TRAININGEVENTNUM FROM CINTRNGEVENT
	WHERE TRAININGEVENTNUM = '#qryECINTRNGENROLLED.TRAININGEVENTNUM#' AND LASTENROLLMENTDATE >= '#qryECINTRNGENROLLED.DATELASTUPDATE#'
</CFQUERY>
<CFSET sMessPostApproval="">
<CFIF qryCINTRNGEVENT.RECORDCOUNT>
	<CFLOOP QUERY="qryECINTRNGEMP">
		<CFQUERY NAME="qryCINTRNGENROLLED" DATASOURCE="#client.company_dsn#">
			SELECT * FROM CINTRNGENROLLED
			WHERE TRAININGEVENTNUM = '#qryECINTRNGENROLLED.TRAININGEVENTNUM#' AND PERSONNELIDNO='#PERSONNELIDNO#'
		</CFQUERY>
		<CFIF qryCINTRNGENROLLED.RECORDCOUNT>
			<CFSET sMessPostApproval="#sMessPostApproval# Employee with PERSONNELIDNO #qryCINTRNGENROLLED.PERSONNELIDNO# already exists in the list of enrolled attendees.<BR>">
		<CFELSE>
			<CFQUERY NAME="qryInsertRecord" DATASOURCE="#client.company_dsn#">
				INSERT INTO CINTRNGENROLLED(TRAININGEVENTNUM,PERSONNELIDNO,REQUESTEDBY,DOCNUMBER,RECCREATEDBY,RECDATECREATED,USERID)
				VALUES('#qryECINTRNGENROLLED.TRAININGEVENTNUM#','#PERSONNELIDNO#','#qryECINTRNGENROLLED.REQUESTEDBY#','#tmpIdDet#','#qryECINTRNGENROLLED.REQUESTEDBY#',<CFIF client.DBMS EQ "ORACLE">to_date(</CFIF>'#DATEFORMAT(Now(),"mm/dd/yyyy")#'<CFIF client.DBMS EQ "ORACLE">, 'mm/dd/yyyy')</CFIF>,'#qryECINTRNGENROLLED.REQUESTEDBY#')
			</CFQUERY>
		</CFIF>
	</CFLOOP>
<CFELSE>
	<CFSET sMessPostApproval="Last day of Enrollment has elapsed. You will not be able to enroll additional Trainees.">
</CFIF>

